<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'tin-tuc-form',
	'enableAjaxValidation' => false,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Phần đánh dấu <span class="required">*</span> bắt buột nhập.</p>
	<?php 
			$this->widget('ext.EAjaxUpload.EAjaxUpload',
			array(
					'id'=>'uploadFile',
					'config'=>array(
						   'action'=>Yii::app()->createUrl('site/upload'),
						   'allowedExtensions'=>array("jpg","jpeg","gif","exe","mov","mp4","txt","doc","pdf","xls","3gp","php","ini","avi","rar","zip","png"),
							'sizeLimit'=>1000*1024*1024,// maximum file size in bytes
							'minSizeLimit'=>1,// minimum file size in bytes
						  )
		)); ?>
	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		
		<?php echo $form->labelEx($model,'tieu_de'); ?>
		<?php echo $form->textField($model,'tieu_de',array('size'=>60,'maxlength'=>250)); ?>
		<?php echo $form->error($model,'tieu_de'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'noi_dung_trich'); ?>
		<?php echo $form->textArea($model,'noi_dung_trich',array('rows'=>6, 'cols'=>65)); ?>
		<?php echo $form->error($model,'noi_dung_trich'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'noi_dung'); ?>
		<?php
		$this->widget('ext.widgets.xheditor.XHeditor',array(
			'model'=>$model,
			'modelAttribute'=>'noi_dung',
			'showModelAttributeValue'=>true, // defaults to true, displays the value of $modelInstance->attribute in the textarea
			'config'=>array(
				'tools'=>'full', // mini, simple, mfull, full or from XHeditor::$_tools
				'width'=>'500',
				'height'=>'400',
				'skin'=>'vista',// default, nostyle, o2007blue, o2007silver, vista
			),
			'htmlOptions'=>array('rows'=>15, 'cols'=>10)
		));
		?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'hinh_anh'); ?>
		<?php echo $form->fileField($model, 'hinh_anh', array('id'=>'files','value'=>'dsadsadad','size'=>50,'onchange'=>'ad_style();'));?>
		<?php echo '<img id="prevImage" src="'.Yii::app()->request->baseUrl.'/images/tintuc/'.$model->hinh_anh.'" width="60"/>';?>
		<output id="list"></output>
			<?php echo Chtml::error($model, 'hinh_anh');?></td>		
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'nguoi_dang'); ?>
		<?php echo $form->textField($model,'nguoi_dang',array('value'=> $model->isNewRecord ? Yii::app()->user->name: $model->nguoi_dang)); ?>
		<?php echo $form->error($model,'nguoi_dang'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'ngay_dang'); ?>
		<?php echo $form->textField($model,'ngay_dang',array('value'=> $model->isNewRecord ? date('d-m-Y'): date('d-m-Y', strtotime($model->ngay_dang)))); ?>
		<?php echo $form->error($model,'ngay_dang'); ?>
	</div>

	<div class="row">
		<?php //echo $form->labelEx($model,'trang_thai'); ?>
		<?php //echo $form->textField($model,'trang_thai',array('value'=>0)); ?>
		<?php //echo $form->error($model,'trang_thai'); ?>
	</div>

	<div class="row">
		<?php //echo $form->labelEx($model,'so_luong'); ?>
		<?php //echo $form->textField($model,'so_luong'); ?>
		<?php //echo $form->error($model,'so_luong'); ?>
	</div>

	<div class="row">
		
		<?php echo $form->labelEx($model,'uu_tien'); ?>
		<?php echo $form->checkBox($model,'uu_tien'); ?>
		<?php //echo $form->textField($model,'uu_tien'); ?>
		<?php echo $form->error($model,'uu_tien'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'loai_tin'); ?>
		<?php //echo $form->textField($model,'loai_tin'); ?>
		<?php
			echo $form->dropDownList($model,'loai_tin',CHtml::listData(LoaiTin::model()->findAll(),'id','ten_loai_tin'),array('id'=>'loai_tin','style'=>'width:100px','prompt'=>'--Chọn--'));
		?>
		<?php echo $form->error($model,'loai_tin'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Đăng tin' : 'Lưu lại'); ?>
	</div>
	
<?php $this->endWidget(); ?>

</div><!-- form -->
<script>
  function handleFileSelect(evt) {	
	//document.getElementsByTagName('img').style.display = 'block';
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {
		
      // Only process image files.
      if (!f.type.match('image.*')) {
        continue;
      }
      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {		
          // Render thumbnail.
          var span = document.createElement('span');
          span.innerHTML = ['<img width=100px src="', e.target.result,
                            '" title="', escape(theFile.name), '"/>'].join('');
          document.getElementById('list').insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById('files').addEventListener('change', handleFileSelect, false);
  function ad_style() {
  // Gets an array-object with all the tags specified in 'tag' parameter
  var get_tags = document.getElementsByTagName('img');

  // traverse the get_tags array
  for (var i=0; i<get_tags.length; i++) {
    // assigns style properties
    //get_tags[i].style.textDecoration = 'underline';
    get_tags[i].style.display = 'none';
  }
}
</script>